package cn.edu.scau.cmi.xuxingao.composite.safe;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class SafeComposite extends SafeComponent{
	
	private String name;
	private List<SafeComponent> children = new ArrayList<SafeComponent>();
	
	public String intro(int i) {
		Iterator<SafeComponent> iter = children.iterator();
		String info="";
		for(int j=0;j<i;j++) {
			info+="       ";
		}
		info=info+"团队："+name;
		while(iter.hasNext()) {
			SafeComponent child = iter.next();
			info = info+'\n'+child.intro(i+1);
		}
		//info+="\n";
		return info;
	};
	
	public SafeComposite() {
		
	}
	public SafeComposite(String name) {
		this.name=name;
	}
	public void add(SafeComponent child) {
		if(child!=null)
			children.add(child);
	}
	
	public void remove(SafeComponent child) {
		if(children.contains(child)) {
			children.remove(child);
		}else {
			System.out.println("团队中无此成员！");
		}
	}
	
	public List<SafeComponent> getChildren(){
		return children;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	public String getName() {
		return name;
	}
	
}

